; Define the coordinates for the clipping rectangle.
; These values should be set according to the window you want to confine the mouse to.
rectX := 100  ; X coordinate of the top-left corner
rectY := 100  ; Y coordinate of the top-left corner
rectWidth := 800  ; Width of the clipping area
rectHeight := 600  ; Height of the clipping area

; Calculate the bottom-right corner coordinates.
rectRight := rectX + rectWidth
rectBottom := rectY + rectHeight

; Create a structure to hold the rectangle's coordinates.
VarSetCapacity(rectangle, 16, 0)  ; RECT structure size: 4*4 = 16 bytes

; Set the coordinates of the rectangle.
NumPut(rectX, rectangle, 0, "Int")  ; Left
NumPut(rectY, rectangle, 4, "Int")  ; Top
NumPut(rectRight, rectangle, 8, "Int")  ; Right
NumPut(rectBottom, rectangle, 12, "Int")  ; Bottom

; Call the ClipCursor function with the address of the rectangle structure.
DllCall("user32.dll\ClipCursor", "Ptr", &rectangle)

; Your script can now continue, and the cursor will be confined to the specified area.

; When you want to release the cursor, call ClipCursor with NULL.
; DllCall("user32.dll\ClipCursor", "Ptr", 0)

; Example: Release the cursor when the script is exiting.
; OnExit, ReleaseCursor

ReleaseCursor() {
    DllCall("user32.dll\ClipCursor", "Ptr", 0)
}

return  ; End of the script